//
//  LeftViewController.m
//  南京大牌档
//
//  Created by student on 14-1-9.
//  Copyright (c) 2014年 无锡第三团队. All rights reserved.
//

#import "LeftViewController.h"
#import "IIViewDeckController.h"
@interface LeftViewController ()

@end

@implementation LeftViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
         self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bj3.jpg"]];

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    
	[self initTableView];
    [self createData];
}
-(void)initTableView
{
    if (WXHLOSVersion()>=7.0) {
        leftTV=[[UITableView alloc]initWithFrame:CGRectMake(0, 20, 140, WXHLApplicationBounds().size.height-20) style:UITableViewStylePlain];
    }
    else{
         leftTV=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 140, WXHLApplicationBounds().size.height-20) style:UITableViewStylePlain];
    }

   
    
    
    
    leftTV.delegate=self;
    leftTV.dataSource=self;
    leftTV.backgroundColor=[UIColor clearColor];
//    leftTV.separatorColor=[UIColor colorWithRed:255/255.0 green:215/255.0 blue:0/255.0 alpha:1];
    [self.view addSubview:leftTV];
}

-(void)createData
{
    foodSections=[[NSArray alloc]initWithObjects:@"官方分类:",@"口味分类:",nil];
    NSDictionary *officialDic1=[[NSDictionary alloc]initWithObjectsAndKeys:@"冷味烧卤",@"title",nil];
    NSDictionary *officialDic2=[[NSDictionary alloc]initWithObjectsAndKeys:@"江南小厨",@"title",nil];
    NSDictionary *officialDic3=[[NSDictionary alloc]initWithObjectsAndKeys:@"牌档食景",@"title",nil];
    NSDictionary *officialDic4=[[NSDictionary alloc]initWithObjectsAndKeys:@"秦淮名点",@"title",nil];
    NSDictionary *officialDic5=[[NSDictionary alloc]initWithObjectsAndKeys:@"酒水饮料",@"title",nil];
    NSDictionary *officialDic6=[[NSDictionary alloc]initWithObjectsAndKeys:@"果汁果盘",@"title",nil];
    NSDictionary *officialDic7=[[NSDictionary alloc]initWithObjectsAndKeys:@"香烟其他",@"title",nil];
    NSDictionary *tasteDic1=[[NSDictionary alloc]initWithObjectsAndKeys:@"偏辣",@"title",nil];
    NSDictionary *tasteDic2=[[NSDictionary alloc]initWithObjectsAndKeys:@"偏甜",@"title",nil];
    NSDictionary *tasteDic3=[[NSDictionary alloc]initWithObjectsAndKeys:@"汤羹",@"title",nil];
    NSDictionary *tasteDic4=[[NSDictionary alloc]initWithObjectsAndKeys:@"主食",@"title",nil];
    NSArray *officialArray=[[NSArray alloc]initWithObjects:officialDic1,officialDic2,officialDic3,officialDic4,officialDic5,officialDic6,officialDic7,nil];
    NSArray *tasteArray=[[NSArray alloc]initWithObjects:tasteDic1,tasteDic2,tasteDic3,tasteDic4, nil];
    foodData=[[NSArray alloc]initWithObjects:officialArray,tasteArray, nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [foodData[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifer=@"Cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if(cell==nil)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    [[cell textLabel] setText:[[[foodData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"title"]];
    cell.textLabel.textColor=[UIColor whiteColor];
    cell.backgroundColor=[UIColor clearColor];
    cell.selectedBackgroundView = [[UIView alloc] init];
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 140, 10)];
    view.backgroundColor=[UIColor clearColor];
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(110, 15, 20, 20)];
    [button setImage:[UIImage imageNamed:@"number_bg"] forState:UIControlStateNormal];
    button.backgroundColor=[UIColor clearColor];
    [view addSubview:button];
    cell.selectedBackgroundView=view;
    
    
       return cell;
}

-(void)changeCenterRow:(int)row Section:(int)section
{
    
    NSNumber *index=[NSNumber numberWithInt:section*10+row];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:index forKey:@"index"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeCenter" object:self userInfo:dic];
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self changeCenterRow:indexPath.row Section:indexPath.section];
    [self.viewDeckController closeLeftViewAnimated:YES];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [foodSections objectAtIndex:section];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
